export interface UserInfo {
    id:number
    account:string
    password:string
    nickName:string
    avatar:string
    email:string
    phone:string
    status:number
    roleId:number
    permission:string
}
export interface InitUserState {
    userInfo:UserInfo | null
}
const initUserState:InitUserState = {
    userInfo:null,
}

export type UserAction = | {type:"set_userInfo",payload:Partial<UserInfo>} | {type:"set_userInfo",payload:null}

//当store调用dispatch的时候，就会走一遍reducer方法
export const userReducer = (state = initUserState,action:UserAction) => {
    switch (action.type) {
        case "set_userInfo":
            //这里可以对数据进行处理，例如更新state中的属性，最终返回新的数据，返回数据后，调用store.getState()就可以获取最新数据了
            return {
                ...state,
                userInfo:action.payload
            }
        default:
            return state
    }
}

